package com.hfi.qinxiaobo151;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ChangLiang
 * @date 2018/9/3
 */
public class Item3_16 {
    public static void main(String[] args) {
        Person02 p1 = new Person02("张三");
        Person02 p2 = new Person02(null);

        List<Person02> l =new ArrayList<Person02>();
        l.add(p1);
        l.add(p2);
        System.out.println("列表中是否包含张三："+l.contains(p1));
        System.out.println("列表中是否包含张三 ："+l.contains(p2));
    }
}

class Person02{
    private String name;

    public Person02(String _name){
        name = _name;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof Person){
            Person p = (Person) obj;
            return name.equalsIgnoreCase(p.getName());
        }
        return false;
    }
}